# -*- coding:utf-8 -*-
from tornado import gen

from common import utiltool
from appcommon.framework import BaseHandler
import models


class VoteListHandler(BaseHandler):
    """
    样例接口
    """
    # @decorator.check_params(['product_type', 'class_id', 'site_id'])
    # @decorator.verify_params
    @gen.coroutine
    def get(self):
        res = []
        vote_list = yield models.get_vote_list()
        for item in vote_list:
            tmp_dict=dict(
                id=item['vote_id'],
                name=item['vote_name'],
                type=item['vote_type'],
                status=item['status'],
                children=[]
            )
            opt_list = yield models.get_opt_list(item['vote_id'])
            for i in opt_list:
                t_dict=dict(
                    id=i['option_id'],
                    name=i['opt_name'],
                    status=item['status'],
                    type=''
                )
                tmp_dict['children'].append(t_dict)
            res.append(tmp_dict)
        # res = [
        #     {
        #     "id":1,
        #     "name":"C",
        #     "size":"",
        #     "date":"02/19/2010",
        #     "children":[
        #         {
        #         "id":2,
        #         "name":"Program Files",
        #         "size":"120 MB",
        #         "date":"03/20/2010",
        #         },
        #         {
        #             "id":22,
        #             "name":"MySQL",
        #             "size":"",
        #             "date":"01/13/2010",
        #         }
        #     ]
        #     },
        #     {
        #         "id":3,
        #         "name":"eclipse",
        #         "size":"",
        #         "date":"01/20/2010",
        #         "children":[{
        #             "id":31,
        #             "name":"eclipse.exe",
        #             "size":"56 KB",
        #             "date":"05/19/2009"
        #         },{
        #             "id":32,
        #             "name":"eclipse.ini",
        #             "size":"1 KB",
        #             "date":"04/20/2010"
        #         },{
        #             "id":33,
        #             "name":"notice.html",
        #             "size":"7 KB",
        #             "date":"03/17/2005"
        #         }]
        #     }]
        utiltool.response_write(self, res)
